package leetcode.code0456;

import leetcode.IDebug;

public class Solution2 implements IDebug {

	public boolean find132pattern(int[] nums) {
		int len = nums.length;
		int[] stack = new int[len];
		int p = 0;
		int[] mins = new int[len];
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < len; i++) {
			int cur = nums[i];
			while (p > 0 && nums[stack[p - 1]] <= cur) {
				p--;
			}
			if (p > 0 && cur > mins[stack[p - 1]]) {
				return true;
			}
			min = Math.min(min, cur);
			mins[i] = min;
			stack[p++] = i;
		}
		return false;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
